package com.modnique;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.UnknownHostException;
import java.text.NumberFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.management.AttributeNotFoundException;

import org.archive.crawler.datamodel.CoreAttributeConstants;
import org.archive.crawler.datamodel.CrawlURI;
import org.archive.crawler.framework.Processor;
import org.archive.crawler.settings.ListType;
import org.archive.crawler.settings.RegularExpressionConstraint;
import org.archive.crawler.settings.SimpleType;
import org.archive.crawler.settings.StringList;
import org.archive.crawler.settings.Type;
import org.archive.io.RecordingInputStream;
import org.archive.io.ReplayInputStream;
import org.archive.net.UURI;
import org.archive.util.IoUtils;

import com.mongodb.MongoException;
import com.nordstrom.NordStromHtmlParser;

public class ModNiqueMirrorWriterProcessor
extends Processor implements CoreAttributeConstants {

    public ModNiqueMirrorWriterProcessor(String name, String description) {
		super(name, "MirrorWriter processor. " +
	            "A writer that writes each URL to a file on disk named for " +
	            "a derivative of the URL.");
	}


	private static final long serialVersionUID = 301407556928389168L;
    
    /**
     * Key to use asking settings for base directory path value.
     */
    public static final String ATTR_PATH = "path";


    protected void innerProcess(CrawlURI curi) {
        if (!curi.isSuccess()) {
            return;
        }
        UURI uuri = curi.getUURI(); // Current URI.
        
        // Only http and https schemes are supported.
        String scheme = uuri.getScheme();
        if (!"http".equalsIgnoreCase(scheme)
                && !"https".equalsIgnoreCase(scheme)) {
            return;
        }
        String url = uuri.toString();
        String regEx_modnique_product = "www\\.modnique\\.com/product/";
    	Pattern pat_modnique_product = Pattern.compile(regEx_modnique_product);
    	Matcher mat_modnique_product = pat_modnique_product.matcher(url);
    	if(mat_modnique_product.find()){
    		ModNiqueHtmlParser modniqueParser = new ModNiqueHtmlParser();
    		
    		try {
				modniqueParser.parserModNique(url);
			} catch (Exception e) {
				e.printStackTrace();
			}
    		
    }
    }
}
